package com.ashlikun.flutter_base_app
import com.ashlikun.flutter_base_app.pigeons.PigeonsConfig
import io.flutter.embedding.android.FlutterActivity
import android.os.Build
import android.os.Bundle
import android.util.Log
import android.view.Window
class MainActivity: FlutterActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        setMaxFps()
        super.onCreate(savedInstanceState)
    }
    override fun configureFlutterEngine(flutterEngine: io.flutter.embedding.engine.FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        PigeonsConfig.configureFlutterEngine(flutterEngine)
    }
    fun setMaxFps() {
        //地图模式默认关闭了高刷
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            val display = windowManager.defaultDisplay
            // 获取系统window支持的模式
            val modes = display.supportedModes
            // 对获取的模式，大小与当前的窗口大小一致，基于刷新率的大小进行排序，从小到大排序
            val modesList = modes.filter { it.physicalWidth == display.width && it.physicalHeight == display.height }.sortedBy { it.refreshRate }
            modesList.forEach {
                Log.e("", "当前刷新模式有：$it")
            }
            Log.e("", "设置的刷新率是：${modesList.last()}")
            modesList.lastOrNull()?.also { mode ->
                window.let {
                    val lp = it.attributes
                    // 取出最大的那一个刷新率Fps，直接设置给window
                    lp.preferredDisplayModeId = mode.modeId
                    it.attributes = lp
                }
            }

        }
    }
}
